Attribute VB_Name = "ModulegbHook"
Option Explicit
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, xyPoint As POINTL) As Long

Public Type POINTL
    x As Long
    y As Long
End Type

Public Type MSLLHOOKSTRUCT
    x As Long
    y As Long
    deltaX As Long
    flags As Long
    Time As Long
    extinfo As Long
End Type


Public Const WH_MOUSE_LL = 14

Public Const WM_MOUSEMOVE = &H200
Public Const WM_MOUSEWHEEL = &H20A

Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202

Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205

Public Const WM_MBUTTONDBLCLK = &H209
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_MBUTTONUP = &H208

Public Const WM_NCLBUTTONDBLCLK = &HA3
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const WM_NCLBUTTONUP = &HA2

Public Const WM_NCMBUTTONDBLCLK = &HA9
Public Const WM_NCMBUTTONDOWN = &HA7
Public Const WM_NCMBUTTONUP = &HA8

Public Const WM_NCMOUSEMOVE = &HA0

Public Const WM_NCRBUTTONDBLCLK = &HA6
Public Const WM_NCRBUTTONDOWN = &HA4
Public Const WM_NCRBUTTONUP = &HA5

Public Const GWL_WNDPROC = (-4)

Public modGMouseEvent As gbMouseEvents
Public modGhWndMouseEvent As hWndEvents
Public Function ReturnAddress(lpAddress As Long) As Long
    ReturnAddress = lpAddress
End Function

Private Function MouseProcA(ByVal ncode As Long, ByVal wp As Long, ByVal lp As Long) As Long
    Call modGMouseEvent.MouseProc_(ncode, wp, lp)
End Function

Public Function GetAddressofG(myGBEvent As gbMouseEvents) As Long
    Set modGMouseEvent = myGBEvent
    GetAddressofG = ReturnAddress(AddressOf MouseProcA)
End Function

Private Function WindowProcA(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Call modGhWndMouseEvent.WindowProc_(hw, uMsg, wParam, lParam)
End Function

Public Function GetAddressofW(modGhWndMouseEvenA As hWndEvents) As Long
    Set modGhWndMouseEvent = modGhWndMouseEvenA
    GetAddressofW = ReturnAddress(AddressOf WindowProcA)
End Function

